package com.pajk.user.api.http;

import java.util.Random;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.pajk.test.api.BaseTest;
import com.pajk.test.client.ContextHelper;
import com.pajk.user.dal.index.TairIndex;
import com.pingan.jk.api.request.ApiCode;
import com.pingan.jk.api.request.Device_CheckSecurity;
import com.pingan.jk.api.request.Device_Register;
import com.pingan.jk.api.request.Sims_CheckIn;
import com.pingan.jk.api.request.User_GradeSafetyAnswersForTrustDevice;
import com.pingan.jk.api.request.User_Login;
import com.pingan.jk.api.request.User_Register;
import com.pingan.jk.api.request.User_RequestSafetyQuestionsForTrustDevice;
import com.pingan.jk.api.request.User_SmsPasswordLogin;
import com.pingan.jk.api.resp.Api_BoolResp;
import com.pingan.jk.api.resp.Api_USER_LoginResp;
import com.pingan.jk.api.resp.Api_USER_RegisterResp;
import com.pingan.jk.api.resp.Api_USER_SafetyQuestion;
import com.pingan.jk.api.resp.Api_USER_SafetyQuestions;
import com.pingan.jk.client.ApiContext;
import com.pingan.jk.client.BaseRequest;
import com.pingan.jk.client.util.Base64Util;

public class User_RegisterIT extends BaseTest{

	private ClassPathXmlApplicationContext appContext = null;
	private TairIndex<Long, Long> mobileToUserIdIndex;

	@BeforeClass
	public void setup() {
//		this.appContext = new ClassPathXmlApplicationContext(
//				"classpath:META-INF/spring/user-service-consumer.xml");
//		this.appContext.start();
//		this.mobileToUserIdIndex = ((TairIndex<Long, Long>)this.appContext.getBean("mobileToUserIdIndex"));
	}

	@AfterClass
	public void teardown() {
//		this.appContext.close();
	}

	//手机号重复注册？？
//	User_Register req3 = new User_Register(false);
//	ContextHelper.sendRequest(context, new BaseRequest[] { req3 });
//	Assert.assertEquals(ApiCode.USER_EXIST_1003040, req3.getReturnCode());
	@Test(description="user.register 使用手机号注册 SecurityType.MobileOwner")
	public void testRegister() {
		ApiContext context = super.registerDevice();
		String phoneNumber = getRandomPhoneNumber();
		System.out.println(phoneNumber);
		context.setPhoneNumberAndDynamic(phoneNumber, "666666");
		User_Register req4 = new User_Register(true);

		ContextHelper.sendRequest(context, new BaseRequest[] { req4 });
		Assert.assertEquals(ApiCode.SUCCESS, req4.getReturnCode());
		Api_USER_RegisterResp res = req4.getResponse();
		System.out.println("[register]expire:"+res.expire+ "   token:"+res.token + "   uid:"+res.uid);
		context.setToken(res.token);

		// 验证：创建user;mobile归属 
		//设备受信等 ...
	}

	@Test
	public void testLogin() {

	}
	


}
